//
//  YBHomeTopHeaderView.m
//  ZhongWangYuanApp
//
//  Created by apple on 18/6/5.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YBHomeTopHeaderView.h"
#import "YBTopDownButton.h"

@interface YBHomeTopHeaderView ()<TitleBannerViewDelegate>

@end

@implementation YBHomeTopHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initMyView];
    }
    return self;
}


-(void)initMyView{
    [self addSubview:self.bannerView];
//    [self initTopItemButton];
    self.bannerView.bannerView.imageNameArray = @[];
}


-(void)initTopItemButton{
    UIView * topButtonContentView = [[UIView alloc]initWithFrame:CGRectMake(0, ItemHeight * 405, [UIScreen zj_screenWith], ItemHeight * 200)];
    topButtonContentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:topButtonContentView];
    
    NSArray * titleArray = @[@"选课" , @"专题" , @"学课" , @"考试"];
    NSArray * imageArray = @[@"icon_ele" , @"icon_topic" , @"icon_xueke" , @"icon_exa"];
    
//    NSArray * titleArray = @[ @"专题" , @"学课" ];
//    NSArray * imageArray = @[ @"icon_topic" , @"icon_xueke" ];
    
    for (int i = 0; i < titleArray.count; i ++) {
        YBTopDownButton * button = [[YBTopDownButton alloc]initWithFrame:CGRectMake([UIScreen zj_screenWith] / titleArray.count * i, 0, [UIScreen zj_screenWith] / titleArray.count, ItemHeight * 200) text:titleArray[i] textColor:[UIColor textGrayColor] imageName:imageArray[i] font:14 imageSize:ItemHeight * 90 theInterval:ItemHeight * 15];
        button.tag = 250 + i;
        [button addTarget:self action:@selector(option_topItemButton:) forControlEvents:UIControlEventTouchUpInside];
        
        [topButtonContentView addSubview:button];
    }
    
    UIView * topBackView = [[UIView alloc]initWithFrame:CGRectMake(0, ItemHeight * 600, [UIScreen zj_screenWith], ItemHeight * 5)];
    topBackView.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:topBackView];
}



-(void)option_topItemButton:(UIButton *)sender{
    NSInteger index = sender.tag - 250;
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickBottomButtonWithIndex:)]) {
        [self.delegate didClickBottomButtonWithIndex:index];
    }
}


-(void)didClickImageViewWithIndex:(NSInteger)index
{
    //点击imageview执行的方法
    if (self.delegate && [self respondsToSelector:@selector(didClickImageViewWithIndex:)]) {
        [self.delegate didClickImageViewWithIndex:index];
    }
    
}


-(void)setBannerArrayWithImageUrlArray:(NSArray *)imageUrlArray{
    NSMutableArray * tempArray = [NSMutableArray array];
    for (NSString * urlString in imageUrlArray) {
        NSString *imageString = [NSString stringWithFormat:@"%@",urlString];
        [tempArray addObject:@{@"url" : CREATEURL(imageString) , @"title" : @""}];
    }
    [self.bannerView initDataSourceWithImageDataArray:[tempArray copy]];
}



-(TitleBannerView *)bannerView
{
    if (!_bannerView) {
        _bannerView = [[TitleBannerView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], ItemHeight * 405)];
        _bannerView.delegate = self;
        UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(([UIScreen zj_screenWith] - 120 * ItemWidth) / 2, ItemHeight * 305, 120 * ItemWidth, 100 * ItemHeight)];
        page.currentPageIndicatorTintColor = [UIColor whiteColor];
        page.pageIndicatorTintColor = [UIColor lightGrayColor];
        page.currentPageIndicatorTintColor = [UIColor whiteColor];
        _bannerView.bannerView.pageControl = page;
        _bannerView.bannerView.isShowPageControl = YES;
        _bannerView.bannerView.isAutoScroll = YES;
//        _bannerView.titleLabel.frame = CGRectMake(ItemPX * 15, 0, [UIScreen zj_screenWith] - ItemPX * 280, ItemPX * 100);
    }
    return _bannerView;
}

@end
